package day0925;

import java.util.TreeMap;

class Cat implements  Comparable{//2.2
    int  age;
    public int compareTo(Object o) {//TreeMap集合根据key的compareTo方法排序
        return this.age- ((Cat)o).age ;//this.值  -  o的值:  升序
    }
}


public class T1 {
    public static void main(String[] args) {
        TreeMap list=new TreeMap();//1. 但是要求元素必须实现Comparable
        Cat  tom=new Cat();     tom.age=10;    list.put(tom, 1001);//2.1.
        Cat  jerry=new Cat();     jerry.age=9;    list.put(jerry, 1008);//2.1.
        System.out.println("list = " + list);
    }
}